package com.cvmars.jianyou.module.adapter;

import android.app.ActivityOptions;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.cvmars.jianyou.R;
import com.cvmars.jianyou.model.UserInfoManager;
import com.cvmars.jianyou.model.UserModel;
import com.cvmars.jianyou.module.activity.PersonHomeActivity;
import com.cvmars.jianyou.module.model.FindCommentModel;
import com.cvmars.jianyou.ui.CircleImageView;
import com.cvmars.jianyou.utils.ImageUtils;
import com.cvmars.jianyou.utils.UtilHelper;

import java.util.List;

/**
 * Created by hehaifeng on 2018/12/24.
 */

public class FindMessageAdapter extends BaseQuickAdapter<FindCommentModel, BaseViewHolder> {

    Context mContext;

    public FindMessageAdapter(Context context, int layoutResId, @Nullable List<FindCommentModel> data) {
        super(layoutResId, data);
        mContext = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, final FindCommentModel item) {


        TextView txtGuanzhu = helper.getView(R.id.txt_guanzhu);

//        if (item.relation_status == 2) {
//
//            txtGuanzhu.setText("互相关注");
//        } else if (item.relation_status == 1) {
//
//            txtGuanzhu.setText("已关注");
//
//        } else if (item.relation_status == -1) {
//
//            txtGuanzhu.setText("关注");
//        }

        helper.setText(R.id.txt_name, item.from_customer.name);
        helper.setText(R.id.txt_time, UtilHelper.forumFriendlyTime(item.create_at));
        helper.getView(R.id.txt_guanzhu).setVisibility(View.INVISIBLE);
        TextView view = helper.getView(R.id.txt_intro);

        if (view != null) {
            view.setText(item.text);
        }

        CircleImageView image = helper.getView(R.id.iv_avator);
        ImageView sex = helper.getView(R.id.iv_sex);

        if (item.from_customer.gender == 1) {

            sex.setImageResource(R.drawable.ic_male);
        } else {

            sex.setImageResource(R.drawable.ic_women);
        }

        ImageUtils.loadImage(mContext, item.from_customer.avatar_url, image);

        image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                onGoHome(item.from_customer.id);
            }
        });

    }


    private void onGoHome( String id) {


        ActivityOptions options = null;

        Intent intent = new Intent(mContext,
                PersonHomeActivity.class);
        intent.putExtra("userid", id);

        mContext.startActivity(intent);

    }
}
